package com.study.sbsummary.utils;

import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;

public final class CoordinateUtil {
    public static final BigDecimal NullCoordinate = new BigDecimal(9999);
    public static final BigDecimal MaxLongitude = new BigDecimal(180);
    public static final BigDecimal MinLongitude = new BigDecimal(-180);
    public static final BigDecimal MaxLatitude = new BigDecimal(90);
    public static final BigDecimal MinLatitude = new BigDecimal(-90);

    private CoordinateUtil() {
    }

    public static BigDecimal getCoordinate(String string) {
        BigDecimal value = NullCoordinate;
        if (!StringUtils.isBlank(string)) {
            value = new BigDecimal(string);
        }

        return value;
    }

    public static boolean valid(BigDecimal lon, BigDecimal lat, boolean checkNull) {
        if (!checkNull && lon.equals(NullCoordinate) && lat.equals(NullCoordinate)) {
            return true;
        } else {
            return lon.compareTo(MinLongitude) == 1 && lon.compareTo(MaxLongitude) == -1 && lat.compareTo(MinLatitude) == 1 && lat.compareTo(MaxLatitude) == -1;
        }
    }

    public static boolean valid(BigDecimal lon, BigDecimal lat) {
        return valid(lon, lat, false);
    }
}
